package com.cctv.fmaed.module.redis.memory.controller;

import com.cctv.fmaed.module.redis.memory.service.DeviceService;
import com.cctv.fmaed.module.redis.memory.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@Slf4j
@RestController
@RequestMapping("device")
public class DeviceController {

    private int DEVICE_SIZE = 500000;
    private int PAD_SIZE = 8;

    private final DeviceService deviceService;

    public DeviceController(DeviceService deviceService) {
        this.deviceService = deviceService;
    }

    @PostMapping("register")
    public Boolean register() throws InterruptedException {
        for (int i = 460080; i < DEVICE_SIZE; i++) {
            log.info("i:[{}]", i);
            String iStr = String.valueOf(i);
            String deviceId = StringUtils.leftPad(iStr, PAD_SIZE, "0");
            String deviceName = "设备名称-" + deviceId;
            deviceService.putDeviceRegister(deviceId, deviceName);
            TimeUnit.MILLISECONDS.sleep(1);
        }
        return Boolean.TRUE;
    }

}
